ARG CENTOS_VERSION=centos8.4.2105
FROM docker.io/library/centos:${CENTOS_VERSION}

RUN minorver=8.5.2111 && sed -e "s|^mirrorlist=|#mirrorlist=|g" \
         -e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$minorver|g" \
         -i.bak \
         /etc/yum.repos.d/CentOS-*.repo
# source code
ADD https://github.com/ApsaraDB/PolarDB-FileSystem/archive/refs/tags/pfsd4pg-release-1.2.42-20220419.tar.gz pfsd4pg.tar.gz
ADD https://github.com/HardySimpson/zlog/archive/refs/tags/1.2.16.tar.gz zlog.tar.gz

# Dependency
RUN dnf makecache && \
    # basic cplusplus tools 
    dnf install -y cmake gcc gcc-c++ \
    # for zlog
    fuse-devel \
    # for pfs
    libaio-devel 

# zlog
# export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/zlog/lib
# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/zlog/lib
# export C_INCLUDE_PATH=${C_INCLUDE_PATH}:/usr/local/zlog/include
# export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/zlog/include

RUN mkdir -p /opt/zlog && \
    tar -zxf /zlog.tar.gz -C /opt/zlog --strip-components=1 && \
    cd /opt/zlog && \
    make PREFIX=/usr/local/zlog && \
    make PREFIX=/usr/local/zlog install && \
    echo "/usr/local/zlog/lib" >> /etc/ld.so.conf 
    #cd / && rm -rf /opt/zlog /zlog.tar.gz

# pfsd4pg
RUN mkdir -p /opt/pfsd4pg  && tar -zxvf /pfsd4pg.tar.gz -C /opt/pfsd4pg --strip-components=1 && \
    cd /opt/pfsd4pg && \
    export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/zlog/lib && \
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/zlog/lib && \
    export C_INCLUDE_PATH=${C_INCLUDE_PATH}:/usr/local/zlog/include && \
    export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/zlog/include && \
    ./autobuild.sh 
    #cd / && rm -rf /opt/pfsd4pg /pfsd4pg.tar.gz